<?php
namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\Model;

class Administrator extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract {
	
	use Authenticatable, Authorizable, CanResetPassword;
	
	protected $guarded = array('id');

	public function avatarUrl() {
		$avatar = $this->avatar;
		if (!starts_with($this->avatar, 'http')) {
			$avatar = asset('/uploads/images/'. $this->avatar);
		}
		return $avatar;
	}
	
	public static $rules = [
		'nickname' => 'required',
		'cellphone' => 'required',
		'password' => 'required',
	];
	
	public static $msgs = [
		'nickname.required' => '昵称不能为空',
		'cellphone.required' => '手机号不能为空',
		'password.required' => '请输入密码',
	];
}
